package com.sf.manager.impl;


import com.sf.manager.LogService;
import org.aspectj.lang.JoinPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component("logService")
public class LogServiceImpl implements LogService {
	@Autowired
	private OperateLogQueue taskLogQueue;

	@SuppressWarnings("unchecked")
	@Override
	public void logArg(JoinPoint point) {
		/*Object[] args = point.getArgs();
		List<Task> tasks = null;
		if (args != null && args.length > 0) {

			if (args[0] instanceof List) {
				tasks = (List<Task>) args[0];
			} else if (args[0] instanceof Map) {
				tasks = Lists.newArrayList();
				Map<Integer, List<List<Task>>> tasksMap = (Map<Integer, List<List<Task>>>) args[0];
				for (Map.Entry<Integer, List<List<Task>>> entry : tasksMap.entrySet()) {
					for (List<Task> temptasks : entry.getValue()) {
						tasks.addAll(temptasks);
					}

				}

			} else if (args[0] instanceof Task) {
				tasks = Lists.newArrayList((Task) args[0]);
			}

			process(tasks);
			}
			*/



	}

	/*private void process(List<Task> tasks) {
		TaskOperateLog taskOperateLog;
		TaskOperateLog taskOperateDetail;
		for (Task task : tasks) {
			if (task.isWriteLog() == null || task.isWriteLog()) {
				taskOperateLog = new TaskOperateLog();
				BeanUtils.copyProperties(task, taskOperateLog);
				taskOperateLog.setId(null);
				taskOperateLog.setTaskId(task.getId());
				taskOperateLog.setOprTm(new Date());
				taskOperateLog.setTaskNo(task.getTaskNo());
				taskLogQueue.add(taskOperateLog);
			}
			if (task.isWriteLog() && task.getTaskDetails() != null && !task.getTaskDetails().isEmpty()) {
				for (TaskDetail detail : task.getTaskDetails()) {
					taskOperateDetail = new TaskOperateLog();
					BeanUtils.copyProperties(task, taskOperateDetail);
					BeanUtils.copyProperties(detail, taskOperateDetail);
					taskOperateDetail.setTaskId(task.getId());
					taskOperateDetail.setDetailState(detail.getState());
					taskOperateDetail.setDetailId(detail.getId());
					taskOperateDetail.setId(null);
					taskOperateDetail.setTaskNo(task.getTaskNo());
					taskOperateDetail.setOprTm(new Date());
					taskLogQueue.add(taskOperateDetail);
				}
			}
		}
	}*/
}
